<template>
  <div class="cell_group">
    <div class="cell">
      <div class="title">
        {{config.attrName}}
      </div>
      <van-switch v-model="switchShow" size="21px" active-color="#4CD964" inactive-color="#E7E7E7" />
    </div>
  </div>
</template>
<script>
export default {
  name: "switch_single",
  props: {
    config: {
      type: Object,
      required: true
    },
    parentIndex: Number,
    itemIndex: Number
  },
  data() {
    return {
      switchShow: false
    };
  },
  created() {
    // if(this.config[this.config.attrKeyName]){
    //   this.config.value = this.config[this.config.attrKeyName]
    // }else{
    //    this.config.value = 'false'
    // }
    if (this.config.value==1) { //1车主为购买人  2车主不是购买人
      this.switchShow = true;
    } else {
      this.config.value = 2;
      this.switchShow = false;
      this.$emit("changeValue", this.parentIndex, this.itemIndex, this.config);

    }
  },
  watch: {
    switchShow(n, o) {
      this.config.value = n?1:2;
      this.$emit("getSwitch", n, this.parentIndex, this.config.attrValueList);
      this.$emit("changeValue", this.parentIndex, this.itemIndex, this.config);
    }
  },
  methods: {}
};
</script>
<style lang="less">
</style>

